package DataStructure.tree.binaryTree.binaryTreeApply;

import DataStructure.tree.binaryTree.binaryTreeImpl.BinaryTreeImpl;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author liujun
 * @version 1.0
 * @date 2020/12/21
 * @author—Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description 判断镜像二叉树
 * 即节点的左孩子值等于右孩子值，是否是一个完全对称的镜像二叉树
 */

public class BT_MirrorJudge {


    public boolean judge(BinaryTreeImpl root) {
        if (root == null) {
            return true;
        }
        return compareTree(root.left, root.right);
    }

    private boolean compareTree(BinaryTreeImpl left, BinaryTreeImpl right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null || left.value != right.value) {
            return false;
        }
        return compareTree(left.left, right.right) && compareTree(left.right, right.left);
    }
}
